Imports Microsoft.VisualBasic
Imports System.Xml
Imports System.Xml.Serialization

<Serializable()> _
Public Class PlayerSetup
    Inherits BaseSetup



    'private
    Private _max As Integer = 100
    Private _min As Integer = 0
    Private _stat_count As Integer = 33


    'extra
    Private _injury_type As String = Cons.NONE
    Private _injury_type_id As Integer = -1
    Private _recovery_left As Integer = 0


    'general
    Private _position As String = Cons.POSITION_GK
    Private _number As Integer
    Private _age As Integer
    Private _retireRange As String = Cons.AGERANGEVAL3
    Private _status As String = Cons.PLAYER_STATUS_ACTIVE    'active or retired

    'attacking
    Private _crossing As Double
    Private _finishing As Double
    Private _heading As Double
    Private _short_pass As Double
    Private _volleys As Double

    'power
    Private _shot_power As Double
    Private _jumping As Double
    Private _stamina As Double
    Private _strength As Double
    Private _long_shot As Double

    'mentality
    Private _aggression As Double
    Private _tactical_awareness As Double
    Private _positioning As Double
    Private _vision As Double
    Private _penalities As Double

    'skill
    Private _curve As Double
    Private _dribbling As Double
    Private _freekick As Double
    Private _long_pass As Double
    Private _ball_control As Double

    'movemnet
    Private _acceleration As Double
    Private _agility As Double
    Private _sprint As Double
    Private _balance As Double
    Private _reactions As Double

    'goalkeeper
    Private _diving As Double
    Private _handling As Double
    Private _kicking As Double
    Private _one_on_one As Double 'gk positioning
    Private _reflexes As Double

    'defending
    Private _marking As Double
    Private _slide_tackle As Double
    Private _standing_tackle As Double


#Region "Properties"

    Public Property Max() As Integer
        Get
            Return _max
        End Get
        Set(ByVal value As Integer)
            Me._max = value
        End Set
    End Property

    Public Property Min() As Integer
        Get
            Return _min
        End Get
        Set(ByVal value As Integer)
            Me._min = value
        End Set
    End Property

    Public Property StatCount() As Integer
        Get
            Return _stat_count
        End Get
        Set(ByVal value As Integer)
            Me._stat_count = value
        End Set
    End Property


    Public Property RecoveryLeft() As Integer
        Get
            Return _recovery_left
        End Get
        Set(ByVal value As Integer)

            Me._recovery_left = value

            If (Me._recovery_left < 0) Then
                Me._recovery_left = 0
            End If


          
        End Set
    End Property

    Public Property InjuryType() As String
        Get
            Return _injury_type
        End Get
        Set(ByVal value As String)
            Me._injury_type = value
        End Set
    End Property

    Public Property InjuryTypeID() As Integer
        Get
            Return _injury_type_id
        End Get
        Set(ByVal value As Integer)
            Me._injury_type_id = value
        End Set
    End Property

    Public Property Position() As String
        Get
            Return _position
        End Get
        Set(ByVal value As String)
            Me._position = value
        End Set
    End Property

    Public Property Number() As Integer
        Get
            Return _number
        End Get
        Set(ByVal value As Integer)
            Me._number = value
        End Set
    End Property

    Public Property Age() As Integer
        Get
            Return _age
        End Get
        Set(ByVal value As Integer)
            Me._age = value
        End Set
    End Property

    Public Property RetireRange() As String
        Get
            Return _retireRange
        End Get
        Set(ByVal value As String)
            _retireRange = value
        End Set
    End Property

    Public Property Status() As String
        Get
            Return _status
        End Get
        Set(ByVal value As String)
            _status = value
        End Set
    End Property

    Public Property Acceleration() As Double
        Get
            Return _acceleration
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._acceleration = Me.Max
            Else
                Me._acceleration = value
            End If
        End Set
    End Property


    Public Property Aggression() As Double
        Get
            Return _aggression
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._aggression = Me.Max
            Else
                Me._aggression = value
            End If

        End Set
    End Property


    Public Property Agility() As Double
        Get
            Return _agility
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._agility = Me.Max
            Else
                Me._agility = value
            End If
        End Set
    End Property


    Public Property Balance() As Double
        Get
            Return _balance
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._balance = Me.Max
            Else
                Me._balance = value
            End If
        End Set
    End Property


    Public Property BallControl() As Double
        Get
            Return _ball_control
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._ball_control = Me.Max
            Else
                Me._ball_control = value
            End If
        End Set
    End Property


    Public Property Crossing() As Double
        Get
            Return _crossing
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._crossing = Me.Max
            Else
                Me._crossing = value
            End If
        End Set
    End Property


    Public Property Curve() As Double
        Get
            Return _curve
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._curve = Me.Max
            Else
                Me._curve = value
            End If
        End Set
    End Property


    Public Property Dribbling() As Double
        Get
            Return _dribbling
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._dribbling = Me.Max
            Else
                Me._dribbling = value
            End If
        End Set
    End Property


    Public Property Finishing() As Double
        Get
            Return _finishing
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._finishing = Me.Max
            Else
                Me._finishing = value
            End If
        End Set
    End Property


    Public Property Freekick() As Double
        Get
            Return _freekick
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._freekick = Me.Max
            Else
                Me._freekick = value
            End If
        End Set
    End Property


    Public Property Diving() As Double
        Get
            Return _diving
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._diving = Me.Max
            Else
                Me._diving = value
            End If
        End Set
    End Property


    Public Property Handling() As Double
        Get
            Return _handling
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._handling = Me.Max
            Else
                Me._handling = value
            End If
        End Set
    End Property


    Public Property Kicking() As Double
        Get
            Return _kicking
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._kicking = Me.Max
            Else
                Me._kicking = value
            End If
        End Set
    End Property


    Public Property One_on_one() As Double
        Get
            Return _one_on_one
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._one_on_one = Me.Max
            Else
                Me._one_on_one = value
            End If
        End Set
    End Property

    Public Property Positioning() As Double
        Get
            Return _positioning
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._positioning = Me.Max
            Else
                Me._positioning = value
            End If
        End Set
    End Property


    Public Property Reflexes() As Double
        Get
            Return _reflexes
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._reflexes = Me.Max
            Else
                Me._reflexes = value
            End If
        End Set
    End Property

    Public Property Heading() As Double
        Get
            Return _heading
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._heading = Me.Max
            Else
                Me._heading = value
            End If
        End Set
    End Property



    Public Property Jumping() As Double
        Get
            Return _jumping
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._jumping = Me.Max
            Else
                Me._jumping = value
            End If
        End Set
    End Property


    Public Property Long_pass() As Double
        Get
            Return _long_pass
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._long_pass = Me.Max
            Else
                Me._long_pass = value
            End If
        End Set
    End Property

    Public Property Long_shot() As Double
        Get
            Return _long_shot
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._long_shot = Me.Max
            Else
                Me._long_shot = value
            End If
        End Set
    End Property


    Public Property Marking() As Double
        Get
            Return _marking
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._marking = Me.Max
            Else
                Me._marking = value
            End If
        End Set
    End Property


    Public Property Penalties() As Double
        Get
            Return _penalities
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._penalities = Me.Max
            Else
                Me._penalities = value
            End If
        End Set
    End Property



    Public Property Reactions() As Double
        Get
            Return _reactions
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._reactions = Me.Max
            Else
                Me._reactions = value
            End If
        End Set
    End Property

    Public Property Short_pass() As Double
        Get
            Return _short_pass
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._short_pass = Me.Max
            Else
                Me._short_pass = value
            End If
        End Set
    End Property


    Public Property Shot_power() As Double
        Get
            Return _shot_power
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._shot_power = Me.Max
            Else
                Me._shot_power = value
            End If
        End Set
    End Property


    Public Property Slide_tackle() As Double
        Get
            Return _slide_tackle
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._slide_tackle = Me.Max
            Else
                Me._slide_tackle = value
            End If
        End Set
    End Property

    Public Property Sprint() As Double
        Get
            Return _sprint
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._sprint = Me.Max
            Else
                Me._sprint = value
            End If
        End Set
    End Property


    Public Property Stamina() As Double
        Get
            Return _stamina
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._stamina = Me.Max
            Else
                Me._stamina = value
            End If
        End Set
    End Property


    Public Property Standing_tackle() As Double
        Get
            Return _standing_tackle
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._standing_tackle = Me.Max
            Else
                Me._standing_tackle = value
            End If
        End Set
    End Property


    Public Property Strength() As Double
        Get
            Return _strength
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._strength = Me.Max
            Else
                Me._strength = value
            End If
        End Set
    End Property


    Public Property Tactical_awareness() As Double
        Get
            Return _tactical_awareness
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._tactical_awareness = Me.Max
            Else
                Me._tactical_awareness = value
            End If
        End Set
    End Property


    Public Property Vision() As Double
        Get
            Return _vision
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._vision = Me.Max
            Else
                Me._vision = value
            End If
        End Set
    End Property


    Public Property Volleys() As Double
        Get
            Return _volleys
        End Get
        Set(ByVal value As Double)
            If (value >= Me.Max) Then
                Me._volleys = Me.Max
            Else
                Me._volleys = value
            End If
        End Set
    End Property

#End Region


#Region "Functions"

    Public Sub UpdateInjuryStatus()
        If Me._recovery_left = 1 Then
            _injury_type = Cons.NONE
            Me._recovery_left = 0
        End If
    End Sub

    Public Function Cap(ByVal value As Double) As Double

        If (value >= Me.Max) Then
            Me._aggression = Me.Max
        Else
            Me._aggression = value
        End If

    End Function

    Public Function GetZone() As String

        Select Case Position
            Case Cons.POSITION_GK
                Return Cons.ZONE_Keeper

            Case Cons.POSITION_SW
                Return Cons.ZONE_Defense
            Case Cons.POSITION_RB
                Return Cons.ZONE_Defense
            Case Cons.POSITION_RWB
                Return Cons.ZONE_Defense
            Case Cons.POSITION_RCB
                Return Cons.ZONE_Defense
            Case Cons.POSITION_CB
                Return Cons.ZONE_Defense
            Case Cons.POSITION_LCB
                Return Cons.ZONE_Defense
            Case Cons.POSITION_LWB
                Return Cons.ZONE_Defense
            Case Cons.POSITION_LB
                Return Cons.ZONE_Defense

            Case Cons.POSITION_RM
                Return Cons.ZONE_Midfield
            Case Cons.POSITION_RAM
                Return Cons.ZONE_Midfield
            Case Cons.POSITION_RCM
                Return Cons.ZONE_Midfield
            Case Cons.POSITION_CM
                Return Cons.ZONE_Midfield
            Case Cons.POSITION_CAM
                Return Cons.ZONE_Midfield
            Case Cons.POSITION_CDM
                Return Cons.ZONE_Midfield
            Case Cons.POSITION_LCM
                Return Cons.ZONE_Midfield
            Case Cons.POSITION_LAM
                Return Cons.ZONE_Midfield
            Case Cons.POSITION_LM
                Return Cons.ZONE_Midfield

            Case Cons.POSITION_RW
                Return Cons.ZONE_Forward
            Case Cons.POSITION_RF
                Return Cons.ZONE_Forward
            Case Cons.POSITION_RS
                Return Cons.ZONE_Forward
            Case Cons.POSITION_CF
                Return Cons.ZONE_Forward
            Case Cons.POSITION_ST
                Return Cons.ZONE_Forward
            Case Cons.POSITION_LS
                Return Cons.ZONE_Forward
            Case Cons.POSITION_LF
                Return Cons.ZONE_Forward
            Case Cons.POSITION_LW
                Return Cons.ZONE_Forward
        End Select

        Return Cons.NONE
    End Function


    Public Function GetAgeRange() As String

        If Age < 16 Then
            Return Cons.AGERANGE1
        ElseIf Age >= 16 And Age < 20 Then
            Return Cons.AGERANGE2
        ElseIf Age >= 20 And Age < 25 Then
            Return Cons.AGERANGE3
        ElseIf Age >= 25 And Age < 30 Then
            Return Cons.AGERANGE4
        ElseIf Age >= 30 And Age < 35 Then
            Return Cons.AGERANGE5
        ElseIf Age >= 35 And Age < 40 Then
            Return Cons.AGERANGE6
        ElseIf Age >= 40 Then
            Return Cons.AGERANGE7
        Else
            Return "Error."
        End If

    End Function

    Public Function IsInjured() As Boolean
        If (_injury_type.Equals(Cons.NONE)) Then
            Return False
        Else
            Return True
        End If

    End Function

    Public Function Overall() As Integer

        Dim total As Integer = 0
        Select Case Position

            Case Cons.POSITION_GK
                'A
                total += (Diving * 24)
                total += (One_on_one * 24)
                total += (Reflexes * 24)
                total += (Handling * 16)
                total += (Kicking * 6)
                total += (Jumping * 3)
                total += (Reactions * 3)

            Case Cons.POSITION_SW
                'B
                total += (Tactical_awareness * 22)
                total += (Marking * 15)
                total += (Standing_tackle * 15)
                total += (Reactions * 9)
                total += (Heading * 7)
                total += (Slide_tackle * 7)
                total += (BallControl * 7)
                total += (Short_pass * 6)
                total += (Strength * 6)
                total += (Acceleration * 4)
                total += (Jumping * 3)

            Case Cons.POSITION_LCB
                'C
                total += (Marking * 20)
                total += (Standing_tackle * 15)
                total += (Heading * 10)
                total += (Slide_tackle * 10)
                total += (Strength * 10)
                total += (Aggression * 10)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Short_pass * 4)
                total += (BallControl * 4)
                total += (Jumping * 4)
                total += (Tactical_awareness * 3)
            Case Cons.POSITION_CB
                'C
                total += (Marking * 20)
                total += (Standing_tackle * 15)
                total += (Heading * 10)
                total += (Slide_tackle * 10)
                total += (Strength * 10)
                total += (Aggression * 10)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Short_pass * 4)
                total += (BallControl * 4)
                total += (Jumping * 4)
                total += (Tactical_awareness * 3)
            Case Cons.POSITION_RCB
                'C
                total += (Marking * 20)
                total += (Standing_tackle * 15)
                total += (Heading * 10)
                total += (Slide_tackle * 10)
                total += (Strength * 10)
                total += (Aggression * 10)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Short_pass * 4)
                total += (BallControl * 4)
                total += (Jumping * 4)
                total += (Tactical_awareness * 3)

            Case Cons.POSITION_LB
                'D
                total += (Marking * 15)
                total += (Standing_tackle * 14)
                total += (Slide_tackle * 10)
                total += (Heading * 8)
                total += (Tactical_awareness * 8)
                total += (BallControl * 7)
                total += (Reactions * 7)
                total += (Short_pass * 6)
                total += (Crossing * 5)
                total += (Stamina * 5)
                total += (Strength * 5)
                total += (Aggression * 5)
                total += (Sprint * 5)

            Case Cons.POSITION_RB
                'D
                total += (Marking * 15)
                total += (Standing_tackle * 14)
                total += (Slide_tackle * 10)
                total += (Heading * 8)
                total += (Tactical_awareness * 8)
                total += (BallControl * 7)
                total += (Reactions * 7)
                total += (Short_pass * 6)
                total += (Crossing * 5)
                total += (Stamina * 5)
                total += (Strength * 5)
                total += (Aggression * 5)
                total += (Sprint * 5)

            Case Cons.POSITION_LWB
                'E
                total += (Marking * 12)
                total += (Standing_tackle * 12)
                total += (BallControl * 10)
                total += (Tactical_awareness * 9)
                total += (Crossing * 8)
                total += (Short_pass * 8)
                total += (Slide_tackle * 8)
                total += (Stamina * 8)
                total += (Heading * 5)
                total += (Dribbling * 5)
                total += (Aggression * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)

            Case Cons.POSITION_RWB
                'E
                total += (Marking * 12)
                total += (Standing_tackle * 12)
                total += (BallControl * 10)
                total += (Tactical_awareness * 9)
                total += (Crossing * 8)
                total += (Short_pass * 8)
                total += (Slide_tackle * 8)
                total += (Stamina * 8)
                total += (Heading * 5)
                total += (Dribbling * 5)
                total += (Aggression * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)

            Case Cons.POSITION_LDM
                'F
                total += (Short_pass * 8)
                total += (Marking * 10)
                total += (Standing_tackle * 10)
                total += (BallControl * 10)
                total += (Tactical_awareness * 10)
                total += (Long_pass * 8)
                total += (Strength * 7)
                total += (Heading * 5)
                total += (Slide_tackle * 5)
                total += (Stamina * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Aggression * 5)
                total += (Vision * 5)
            Case Cons.POSITION_CDM
                'F
                total += (Short_pass * 8)
                total += (Marking * 10)
                total += (Standing_tackle * 10)
                total += (BallControl * 10)
                total += (Tactical_awareness * 10)
                total += (Long_pass * 8)
                total += (Strength * 7)
                total += (Heading * 5)
                total += (Slide_tackle * 5)
                total += (Stamina * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Aggression * 5)
                total += (Vision * 5)
            Case Cons.POSITION_RDM
                'F
                total += (Short_pass * 8)
                total += (Marking * 10)
                total += (Standing_tackle * 10)
                total += (BallControl * 10)
                total += (Tactical_awareness * 10)
                total += (Long_pass * 8)
                total += (Strength * 7)
                total += (Heading * 5)
                total += (Slide_tackle * 5)
                total += (Stamina * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Aggression * 5)
                total += (Vision * 5)

            Case Cons.POSITION_LCM
                'G
                total += (Short_pass * 15)
                total += (Long_pass * 12)
                total += (Dribbling * 10)
                total += (BallControl * 10)
                total += (Vision * 10)
                total += (Positioning * 6)
                total += (Heading * 5)
                total += (Standing_tackle * 5)
                total += (Stamina * 5)
                total += (Long_shot * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Strength * 4)
                total += (Tactical_awareness * 3)
            Case Cons.POSITION_CM
                'G
                total += (Short_pass * 15)
                total += (Long_pass * 12)
                total += (Dribbling * 10)
                total += (BallControl * 10)
                total += (Vision * 10)
                total += (Positioning * 6)
                total += (Heading * 5)
                total += (Standing_tackle * 5)
                total += (Stamina * 5)
                total += (Long_shot * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Strength * 4)
                total += (Tactical_awareness * 3)
            Case Cons.POSITION_RCM
                'G
                total += (Short_pass * 15)
                total += (Long_pass * 12)
                total += (Dribbling * 10)
                total += (BallControl * 10)
                total += (Vision * 10)
                total += (Positioning * 6)
                total += (Heading * 5)
                total += (Standing_tackle * 5)
                total += (Stamina * 5)
                total += (Long_shot * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Strength * 4)
                total += (Tactical_awareness * 3)


            Case Cons.POSITION_LM
                'H
                total += (Crossing * 13)
                total += (Dribbling * 13)
                total += (Short_pass * 12)
                total += (BallControl * 12)
                total += (Sprint * 8)
                total += (Long_pass * 7)
                total += (Acceleration * 7)
                total += (Positioning * 6)
                total += (Vision * 6)
                total += (Stamina * 5)
                total += (Reactions * 5)
                total += (Agility * 3)
                total += (Long_shot * 3)
            Case Cons.POSITION_RM
                'H
                total += (Crossing * 13)
                total += (Dribbling * 13)
                total += (Short_pass * 12)
                total += (BallControl * 12)
                total += (Sprint * 8)
                total += (Long_pass * 7)
                total += (Acceleration * 7)
                total += (Positioning * 6)
                total += (Vision * 6)
                total += (Stamina * 5)
                total += (Reactions * 5)
                total += (Agility * 3)
                total += (Long_shot * 3)

            Case Cons.POSITION_LAM
                'I
                total += (Short_pass * 15)
                total += (Dribbling * 12)
                total += (BallControl * 12)
                total += (Vision * 10)
                total += (Long_shot * 9)
                total += (Positioning * 9)
                total += (Finishing * 7)
                total += (Long_pass * 7)
                total += (Shot_power * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Heading * 4)
            Case Cons.POSITION_CAM
                'I
                total += (Short_pass * 15)
                total += (Dribbling * 12)
                total += (BallControl * 12)
                total += (Vision * 10)
                total += (Long_shot * 9)
                total += (Positioning * 9)
                total += (Finishing * 7)
                total += (Long_pass * 7)
                total += (Shot_power * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Heading * 4)
            Case Cons.POSITION_RAM
                'I
                total += (Short_pass * 15)
                total += (Dribbling * 12)
                total += (BallControl * 12)
                total += (Vision * 10)
                total += (Long_shot * 9)
                total += (Positioning * 9)
                total += (Finishing * 7)
                total += (Long_pass * 7)
                total += (Shot_power * 5)
                total += (Sprint * 5)
                total += (Reactions * 5)
                total += (Heading * 4)

            Case Cons.POSITION_LW
                'J
                total += (Dribbling * 15)
                total += (Crossing * 12)
                total += (Acceleration * 11)
                total += (Short_pass * 10)
                total += (BallControl * 10)
                total += (Sprint * 9)
                total += (Long_pass * 5)
                total += (Agility * 5)
                total += (Reactions * 5)
                total += (Finishing * 4)
                total += (Stamina * 4)
                total += (Vision * 4)
                total += (Shot_power * 35)
                total += (Long_shot * 3)
            Case Cons.POSITION_RW
                'J
                total += (Dribbling * 15)
                total += (Crossing * 12)
                total += (Acceleration * 11)
                total += (Short_pass * 10)
                total += (BallControl * 10)
                total += (Sprint * 9)
                total += (Long_pass * 5)
                total += (Agility * 5)
                total += (Reactions * 5)
                total += (Finishing * 4)
                total += (Stamina * 4)
                total += (Vision * 4)
                total += (Shot_power * 35)
                total += (Long_shot * 3)

            Case Cons.POSITION_CF
                'K
                total += (Finishing * 17)
                total += (Dribbling * 12)
                total += (BallControl * 11)
                total += (Shot_power * 9)
                total += (Long_shot * 8)
                total += (Acceleration * 8)
                total += (Sprint * 8)
                total += (Reactions * 8)
                total += (Heading * 5)
                total += (Short_pass * 5)
                total += (Crossing * 3)
                total += (Volleys * 3)
                total += (Strength * 3)

            Case Cons.POSITION_LF
                'L
                total += (Finishing * 12)
                total += (Dribbling * 12)
                total += (BallControl * 10)
                total += (Long_shot * 9)
                total += (Crossing * 3)
                total += (Shot_power * 9)
                total += (Acceleration * 8)
                total += (Sprint * 8)
                total += (Reactions * 8)
                total += (Heading * 5)
                total += (Short_pass * 5)
                total += (Volleys * 4)
                total += (Strength * 3)
            Case Cons.POSITION_RF
                'L
                total += (Finishing * 12)
                total += (Dribbling * 12)
                total += (BallControl * 10)
                total += (Long_shot * 9)
                total += (Crossing * 3)
                total += (Shot_power * 9)
                total += (Acceleration * 8)
                total += (Sprint * 8)
                total += (Reactions * 8)
                total += (Heading * 5)
                total += (Short_pass * 5)
                total += (Volleys * 4)
                total += (Strength * 3)


            Case Cons.POSITION_ST
                'M
                total += (Finishing * 20)
                total += (Heading * 10)
                total += (Shot_power * 10)
                total += (Acceleration * 10)
                total += (Dribbling * 8)
                total += (Reactions * 8)
                total += (BallControl * 7)
                total += (Long_shot * 7)
                total += (Short_pass * 5)
                total += (Volleys * 5)
                total += (Strength * 5)
                total += (Sprint * 5)
            Case Cons.POSITION_LS
                'M
                total += (Finishing * 20)
                total += (Heading * 10)
                total += (Shot_power * 10)
                total += (Acceleration * 10)
                total += (Dribbling * 8)
                total += (Reactions * 8)
                total += (BallControl * 7)
                total += (Long_shot * 7)
                total += (Short_pass * 5)
                total += (Volleys * 5)
                total += (Strength * 5)
                total += (Sprint * 5)
            Case Cons.POSITION_RS
                'M
                total += (Finishing * 20)
                total += (Heading * 10)
                total += (Shot_power * 10)
                total += (Acceleration * 10)
                total += (Dribbling * 8)
                total += (Reactions * 8)
                total += (BallControl * 7)
                total += (Long_shot * 7)
                total += (Short_pass * 5)
                total += (Volleys * 5)
                total += (Strength * 5)
                total += (Sprint * 5)

        End Select

        Dim ov As Integer = CInt(total / 100.0)

        Return ov

    End Function

    Public Function ProbabiltyOfInjury()
        'aggression
        'agility
        'balance
        'reaction
        'strength

        Dim total As Double = 500.0
        Dim sum As Double = (100.0 - Me._aggression) + Me._agility + Me._balance + Me._reactions + Me._strength

        Dim prob As Double = 1.0 - (sum / total)    '(500.0 / ((100.0 - (Me._aggression + _aggression_inc) + (Me._agility + Me._agility_inc) + (Me._balance + Me._balance_inc) + (Me._reactions + Me._reactions_inc) + (Me._strength + Me._strength_inc))) / 1.0) - 1.0

        Return prob
    End Function

    Public Function Increment(ByVal attribute As String, ByVal inc As Double) As Boolean

        Select Case (attribute)

            Case Cons.ATTRIBUTE_Crossing
                Crossing += inc
            Case Cons.ATTRIBUTE_Finishing
                Finishing += inc
            Case Cons.ATTRIBUTE_Heading
                Heading += inc
            Case Cons.ATTRIBUTE_Short_Pass
                Short_pass += inc
            Case Cons.ATTRIBUTE_Volleys
                Volleys += inc
            Case Cons.ATTRIBUTE_Shot_Power
                Shot_power += inc
            Case Cons.ATTRIBUTE_Jumping
                Jumping += inc
            Case Cons.ATTRIBUTE_Stamina
                Stamina += inc
            Case Cons.ATTRIBUTE_Strength
                Strength += inc
            Case Cons.ATTRIBUTE_Long_Shot
                Long_shot += inc
            Case Cons.ATTRIBUTE_Aggression
                Aggression += inc
            Case Cons.ATTRIBUTE_Tactical_Awareness
                Tactical_awareness += inc
            Case Cons.ATTRIBUTE_Positioning
                Positioning += inc
            Case Cons.ATTRIBUTE_Vision
                Vision += inc
            Case Cons.ATTRIBUTE_Penalties
                Penalties += inc
            Case Cons.ATTRIBUTE_Curve
                Curve += inc
            Case Cons.ATTRIBUTE_Dribbling
                Dribbling += inc
            Case Cons.ATTRIBUTE_Freekick
                Freekick += inc
            Case Cons.ATTRIBUTE_Long_Pass
                Long_pass += inc
            Case Cons.ATTRIBUTE_Ball_Control
                BallControl += inc
            Case Cons.ATTRIBUTE_Acceleration
                Acceleration += inc
            Case Cons.ATTRIBUTE_Agility
                Agility += inc
            Case Cons.ATTRIBUTE_Sprint
                Sprint += inc
            Case Cons.ATTRIBUTE_Balance
                Balance += inc
            Case Cons.ATTRIBUTE_Reactions
                Reactions += inc
            Case Cons.ATTRIBUTE_Marking
                Marking += inc
            Case Cons.ATTRIBUTE_Slide_Tackle
                Slide_tackle += inc
            Case Cons.ATTRIBUTE_Standing_Tackle
                Standing_tackle += inc
            Case Cons.ATTRIBUTE_Diving
                Diving += inc
            Case Cons.ATTRIBUTE_Handling
                Handling += inc
            Case Cons.ATTRIBUTE_Kicking
                Kicking += inc
            Case Cons.ATTRIBUTE_One_On_One
                One_on_one += inc
            Case Cons.ATTRIBUTE_Reflexes
                Reflexes += inc
        End Select
    End Function

    Public Function AttemptToRetire() As Boolean

        If Status.Equals(Cons.PLAYER_STATUS_RETIRED) Then
            Return True

        Else
            'active
            If _retireRange.Equals(Cons.AGERANGEVAL1) Then
                If Age >= 30 Then
                    _status = Cons.PLAYER_STATUS_RETIRED
                    Return True
                End If
            ElseIf _retireRange.Equals(Cons.AGERANGEVAL2) Then
                If Age >= 35 Then
                    _status = Cons.PLAYER_STATUS_RETIRED
                    Return True
                End If
            ElseIf _retireRange.Equals(Cons.AGERANGEVAL3) Then
                If Age >= 40 Then
                    _status = Cons.PLAYER_STATUS_RETIRED
                    Return True
                End If

            End If
        End If

        Return False

    End Function
#End Region

    Public Overrides Function SetupToXML() As String
        Dim xml As String = "" '<Player id=""" & Me._id & """ name =""" & Me._name & """ age=""" & Me._age & """ pos=""" & Me._pos & """>"

        xml &= "<Setup>" & System.Environment.NewLine

        xml &= "<General>" & System.Environment.NewLine
        xml &= "<position>" & Me._position & "</position>" & System.Environment.NewLine
        xml &= "<number>" & Me._number & "</number>" & System.Environment.NewLine
        xml &= "<age>" & Me._age & "</age>" & System.Environment.NewLine
        xml &= "<retireRange>" & Me._retireRange & "</retireRange>" & System.Environment.NewLine
        xml &= "<status>" & Me._status & "</status>" & System.Environment.NewLine
        xml &= "</General>" & System.Environment.NewLine

        xml &= "<Injury>" & System.Environment.NewLine
        xml &= "<injurytype>" & Me._injury_type & "</injurytype>" & System.Environment.NewLine
        xml &= "<injurytypeid>" & Me._injury_type_id & "</injurytypeid>" & System.Environment.NewLine

        xml &= "<recoveryleft>" & Me._recovery_left & "</recoveryleft>" & System.Environment.NewLine
        xml &= "</Injury>" & System.Environment.NewLine

        xml &= "<Attacking>" & System.Environment.NewLine
        xml &= "<crossing>" & Me._crossing & "</crossing>" & System.Environment.NewLine
        xml &= "<finishing>" & Me._finishing & "</finishing>" & System.Environment.NewLine
        xml &= "<heading>" & Me._heading & "</heading>" & System.Environment.NewLine
        xml &= "<shortpass>" & Me._short_pass & "</shortpass>" & System.Environment.NewLine
        xml &= "<volleys>" & Me._volleys & "</volleys>" & System.Environment.NewLine
        xml &= "</Attacking>" & System.Environment.NewLine

        xml &= "<Power>" & System.Environment.NewLine
        xml &= "<shotpower>" & Me._shot_power & "</shotpower>" & System.Environment.NewLine
        xml &= "<jumping>" & Me._jumping & "</jumping>" & System.Environment.NewLine
        xml &= "<longshot>" & Me._long_shot & "</longshot>" & System.Environment.NewLine
        xml &= "<stamina>" & Me._stamina & "</stamina>" & System.Environment.NewLine
        xml &= "<strength>" & Me._strength & "</strength>" & System.Environment.NewLine
        xml &= "</Power>" & System.Environment.NewLine

        xml &= "<Mentality>" & System.Environment.NewLine
        xml &= "<aggression>" & Me._aggression & "</aggression>" & System.Environment.NewLine
        xml &= "<penalities>" & Me._penalities & "</penalities>" & System.Environment.NewLine
        xml &= "<positioning>" & Me._positioning & "</positioning>" & System.Environment.NewLine
        xml &= "<tacticalawareness>" & Me._tactical_awareness & "</tacticalawareness>" & System.Environment.NewLine
        xml &= "<vision>" & Me._vision & "</vision>" & System.Environment.NewLine
        xml &= "</Mentality>" & System.Environment.NewLine

        xml &= "<Skill>" & System.Environment.NewLine
        xml &= "<ballcontrol>" & Me._ball_control & "</ballcontrol>" & System.Environment.NewLine
        xml &= "<curve>" & Me._curve & "</curve>" & System.Environment.NewLine
        xml &= "<dribbling>" & Me._dribbling & "</dribbling>" & System.Environment.NewLine
        xml &= "<freekick>" & Me._freekick & "</freekick>" & System.Environment.NewLine
        xml &= "<longpass>" & Me._long_pass & "</longpass>" & System.Environment.NewLine
        xml &= "</Skill>" & System.Environment.NewLine

        xml &= "<Movement>" & System.Environment.NewLine
        xml &= "<acceleration>" & Me._acceleration & "</acceleration>" & System.Environment.NewLine
        xml &= "<agility>" & Me._agility & "</agility>" & System.Environment.NewLine
        xml &= "<balance>" & Me._balance & "</balance>" & System.Environment.NewLine
        xml &= "<reactions>" & Me._reactions & "</reactions>" & System.Environment.NewLine
        xml &= "<sprint>" & Me._sprint & "</sprint>" & System.Environment.NewLine
        xml &= "</Movement>" & System.Environment.NewLine

        xml &= "<Goalkeeper>" & System.Environment.NewLine
        xml &= "<diving>" & Me._diving & "</diving>" & System.Environment.NewLine
        xml &= "<handling>" & Me._handling & "</handling>" & System.Environment.NewLine
        xml &= "<kicking>" & Me._kicking & "</kicking>" & System.Environment.NewLine
        xml &= "<oneonone>" & Me._one_on_one & "</oneonone>" & System.Environment.NewLine
        xml &= "<reflexes>" & Me._reflexes & "</reflexes>" & System.Environment.NewLine
        xml &= "</Goalkeeper>" & System.Environment.NewLine

        xml &= "<Defending>" & System.Environment.NewLine
        xml &= "<marking>" & Me._marking & "</marking>" & System.Environment.NewLine
        xml &= "<slidetackle>" & Me._slide_tackle & "</slidetackle>" & System.Environment.NewLine
        xml &= "<standingtackle>" & Me._standing_tackle & "</standingtackle>" & System.Environment.NewLine
        xml &= "</Defending>" & System.Environment.NewLine

        xml &= "</Setup>"

        Return xml
    End Function

    Public Overrides Function XMLToSetup(ByVal xml As String) As BaseSetup
        Dim doc As New XmlDocument

        If (Not xml.Equals("<Setup />")) Then
            doc.LoadXml(xml)


            _position = doc.GetElementsByTagName("position").ItemOf(0).InnerText
            _number = doc.GetElementsByTagName("number").ItemOf(0).InnerText
            _age = doc.GetElementsByTagName("age").ItemOf(0).InnerText
            _retireRange = doc.GetElementsByTagName("retireRange").ItemOf(0).InnerText
            _status = doc.GetElementsByTagName("status").ItemOf(0).InnerText
            _injury_type_id = doc.GetElementsByTagName("injurytypeid").ItemOf(0).InnerText

            Dim _injurybase As Base = Nothing

            If (_injury_type_id <> -1) Then

                _injurybase = DBConnection.FET_INJURY(_injury_type_id)

                If _injurybase Is Nothing Then
                    'a selected injury id that has been deleted

                    _injury_type = Cons.NONE

                    _recovery_left = 0
                    _injury_type_id = -1
                    Update = True
                Else
                    'a selected injury id that still exists
                    _injury_type = doc.GetElementsByTagName("injurytype").ItemOf(0).InnerText
                    _recovery_left = doc.GetElementsByTagName("recoveryleft").ItemOf(0).InnerText

                End If
            Else
                '-1 was selected.
                _injury_type = Cons.NONE

                _recovery_left = 0
                _injury_type_id = -1
            End If




            _crossing = doc.GetElementsByTagName("crossing").ItemOf(0).InnerText
            _finishing = doc.GetElementsByTagName("finishing").ItemOf(0).InnerText
            _heading = doc.GetElementsByTagName("heading").ItemOf(0).InnerText
            _short_pass = doc.GetElementsByTagName("shortpass").ItemOf(0).InnerText
            _volleys = doc.GetElementsByTagName("volleys").ItemOf(0).InnerText


            _shot_power = doc.GetElementsByTagName("shotpower").ItemOf(0).InnerText
            _jumping = doc.GetElementsByTagName("jumping").ItemOf(0).InnerText
            _long_shot = doc.GetElementsByTagName("longshot").ItemOf(0).InnerText
            _stamina = doc.GetElementsByTagName("stamina").ItemOf(0).InnerText
            _strength = doc.GetElementsByTagName("strength").ItemOf(0).InnerText


            _aggression = doc.GetElementsByTagName("aggression").ItemOf(0).InnerText
            _penalities = doc.GetElementsByTagName("penalities").ItemOf(0).InnerText
            _positioning = doc.GetElementsByTagName("positioning").ItemOf(0).InnerText
            _tactical_awareness = doc.GetElementsByTagName("tacticalawareness").ItemOf(0).InnerText
            _vision = doc.GetElementsByTagName("vision").ItemOf(0).InnerText


            _ball_control = doc.GetElementsByTagName("ballcontrol").ItemOf(0).InnerText
            _curve = doc.GetElementsByTagName("curve").ItemOf(0).InnerText
            _dribbling = doc.GetElementsByTagName("dribbling").ItemOf(0).InnerText
            _freekick = doc.GetElementsByTagName("freekick").ItemOf(0).InnerText
            _long_pass = doc.GetElementsByTagName("longpass").ItemOf(0).InnerText


            _acceleration = doc.GetElementsByTagName("acceleration").ItemOf(0).InnerText
            _agility = doc.GetElementsByTagName("agility").ItemOf(0).InnerText
            _balance = doc.GetElementsByTagName("balance").ItemOf(0).InnerText
            _reactions = doc.GetElementsByTagName("reactions").ItemOf(0).InnerText
            _sprint = doc.GetElementsByTagName("sprint").ItemOf(0).InnerText


            _diving = doc.GetElementsByTagName("diving").ItemOf(0).InnerText
            _handling = doc.GetElementsByTagName("handling").ItemOf(0).InnerText
            _kicking = doc.GetElementsByTagName("kicking").ItemOf(0).InnerText
            _one_on_one = doc.GetElementsByTagName("oneonone").ItemOf(0).InnerText
            _reflexes = doc.GetElementsByTagName("reflexes").ItemOf(0).InnerText



            _marking = doc.GetElementsByTagName("marking").ItemOf(0).InnerText
            _slide_tackle = doc.GetElementsByTagName("slidetackle").ItemOf(0).InnerText
            _standing_tackle = doc.GetElementsByTagName("standingtackle").ItemOf(0).InnerText


        End If

        Return Me
    End Function

    Public Overrides Function Clone() As BaseSetup

        Dim _clone As New PlayerSetup
        _clone.Max = Me._max
        _clone.Min = Me._min
        _clone.StatCount = Me._stat_count

        _clone.Age = Me._age
        _clone.Position = Me._position
        _clone.Number = Me._number
        _clone.RetireRange = Me._retireRange
        _clone.Status = Me._status

        _clone.InjuryType = Me._injury_type
        _clone.RecoveryLeft = Me._recovery_left

        _clone.Crossing = Me._crossing
        _clone.Finishing = Me._finishing
        _clone.Heading = Me._heading
        _clone.Short_pass = Me._short_pass
        _clone.Volleys = Me._volleys


        _clone.Shot_power = Me._shot_power
        _clone.Jumping = Me._jumping
        _clone.Stamina = Me._stamina
        _clone.Strength = Me._strength
        _clone.Long_shot = Me._long_shot


        _clone.Aggression = Me._aggression
        _clone.Tactical_awareness = Me._tactical_awareness
        _clone.Positioning = Me._positioning
        _clone.Vision = Me._vision
        _clone.Penalties = Me._penalities

        _clone.Curve = Me._curve
        _clone.Dribbling = Me._dribbling
        _clone.Freekick = Me._freekick
        _clone.Long_pass = Me._long_pass
        _clone.BallControl = Me._ball_control


        _clone.Acceleration = Me._acceleration
        _clone.Agility = Me._agility
        _clone.Sprint = Me._sprint
        _clone.Balance = Me._balance
        _clone.Reactions = Me._reactions


        _clone.Diving = Me._diving
        _clone.Handling = Me._handling
        _clone.Kicking = Me._kicking
        _clone.One_on_one = Me._one_on_one
        _clone.Reflexes = Me._reflexes


        _clone.Marking = Me._marking
        _clone.Slide_tackle = Me._slide_tackle
        _clone.Standing_tackle = Me._standing_tackle

        Return _clone
    End Function

    Public Overrides Function ToString() As String

        Dim str As String = ""

        str &= "Overall    :" & Me.Overall & Environment.NewLine
        str &= "P(I)    :" & Me.ProbabiltyOfInjury & Environment.NewLine

        str &= "Age     :" & Me._age & Environment.NewLine
        str &= "Position: " & Me._position & Environment.NewLine
        str &= "Number  :" & Me._number & Environment.NewLine
        str &= "RetireRange  :" & Me._retireRange & Environment.NewLine
        str &= "Status  :" & Me._status & Environment.NewLine

        str &= "Injury Type  :" & Me._injury_type & Environment.NewLine
        str &= "Recovery Left:" & Me._recovery_left & Environment.NewLine

        str &= "Crossing   :" & Me._crossing & Environment.NewLine
        str &= "Finishing  :" & Me._finishing & Environment.NewLine
        str &= "Heading    :" & Me._heading & Environment.NewLine
        str &= "Short Pass :" & Me._short_pass & Environment.NewLine
        str &= "Volleys    :" & Me._volleys & Environment.NewLine


        str &= "Shot Power:" & Me._shot_power & Environment.NewLine
        str &= "Jumping   :" & Me._jumping & Environment.NewLine
        str &= "Stamina   :" & Me._stamina & Environment.NewLine
        str &= "Strength  :" & Me._strength & Environment.NewLine
        str &= "Long Shot :" & Me._long_shot & Environment.NewLine


        str &= "Aggression :" & Me._aggression & Environment.NewLine
        str &= "Tact. Awar.:" & Me._tactical_awareness & Environment.NewLine
        str &= "Positioning:" & Me._positioning & Environment.NewLine
        str &= "Vision     :" & Me._vision & Environment.NewLine
        str &= "Penalties  :" & Me._penalities & Environment.NewLine

        str &= "Curve      :" & Me._curve & Environment.NewLine
        str &= "Dribbling  :" & Me._dribbling & Environment.NewLine
        str &= "Freekick   :" & Me._freekick & Environment.NewLine
        str &= "Long Pass  :" & Me._long_pass & Environment.NewLine
        str &= "Ball Control:" & Me._ball_control & Environment.NewLine


        str &= "Acceleration:" & Me._acceleration & Environment.NewLine
        str &= "Agility     :" & Me._agility & Environment.NewLine
        str &= "Sprint      :" & Me._sprint & Environment.NewLine
        str &= "Balance     :" & Me._balance & Environment.NewLine
        str &= "Reactions   :" & Me._reactions & Environment.NewLine


        str &= "Diving      :" & Me._diving & Environment.NewLine
        str &= "Handling    :" & Me._handling & Environment.NewLine
        str &= "Kicking     :" & Me._kicking & Environment.NewLine
        str &= "One on One  :" & Me._one_on_one & Environment.NewLine
        str &= "Reflexes    :" & Me._reflexes & Environment.NewLine


        str &= "Marking     :" & Me._marking & Environment.NewLine
        str &= "Slide Tackle:" & Me._slide_tackle & Environment.NewLine
        str &= "Stand Tackle:" & Me._standing_tackle & Environment.NewLine


        Return str
    End Function

    Public Overrides Function ValidateBaseSetup() As Collection

    End Function

    Public Overrides Function DefaultXML() As String
        Return "<Setup />"
    End Function
End Class
